<?php
// 系统数据模型，主要是一些逻辑上比较复杂的实现后台系统功能的数据模型
class Film_model extends CI_Model {

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function get_new_film($cateId,$num)
    {
        $sql = "SELECT
                    *
                FROM
                    tb_film_list
                WHERE
                    cate_id = {$cateId}
                AND has_download = 1
                ORDER BY
                    id DESC
                LIMIT 0,
                 {$num}";
        return $this->db->query($sql)->result_array();
    }

    public function get_film_download($keywords)
    {

        $sql = "select id,name from tb_film_list where name like '%{$keywords}%' and has_download = 1";
        $filmInfo = $this->db->query($sql)->row_array();
        if(!$filmInfo){
            return null;
        }
        $sql2 = "select * from tb_film_download where film_id = {$filmInfo['id']}";
        $downloadInfo = $this->db->query($sql2)->row_array();
        if(!$downloadInfo){
            return null;
        }
        $this->load->library('lw_thunder');
        $info = array(
            'name'=>$filmInfo['name'],
            'code'=>$this->lw_thunder->thunderEncode($downloadInfo['download_url']),
        );
        return $info;
    }

}